package main

import (
	"fmt"
)

// 创建结构体的四种方式
func main() {
	build01()
	build02()
	build03()
	build04()
}

// build01
//
//	@Description: 先定义，后赋值
func build01() {
	fmt.Println("-------------先定义，后赋值-------------")
	var zhangsan Stu
	zhangsan.Name = "zhangsan"
	zhangsan.Age = 18
	zhangsan.Sex = true
	fmt.Println(zhangsan) //{zhangsan 18 true}
}

// build02
//
//	@Description: 直接赋值
func build02() {
	fmt.Println("-------------直接赋值-------------")
	var lisi01 Stu = Stu{"lisi01", 20, false}
	fmt.Println(lisi01) //{lisi01 20 false}

	var lisi02 Stu = Stu{Name: "lisi02", Age: 18, Sex: false}
	fmt.Println(lisi02)

	lisi03 := Stu{"lisi03", 30, true}
	fmt.Println(lisi03) //{lisi03 30 true}

	lisi04 := Stu{Name: "lisi04", Age: 30, Sex: true}
	fmt.Println(lisi04) //{lisi04 30 true}
}

// build03
//
//	@Description: new返回指针
func build03() {
	fmt.Println("-------------new返回指针-------------")
	var zhaoliu01 *Stu = new(Stu)
	(*zhaoliu01).Name = "zhaoliu01"
	(*zhaoliu01).Age = 20
	(*zhaoliu01).Sex = false
	fmt.Println(*zhaoliu01) //{zhaoliu01 20 false}

	zhaoliu02 := new(Stu)
	(*zhaoliu02).Name = "zhaoliu02"
	(*zhaoliu02).Age = 20
	(*zhaoliu02).Sex = false
	fmt.Println(*zhaoliu02)
}

// build04
//
//	@Description: &返回指针
func build04() {
	fmt.Println("-------------&返回指针-------------")

	var tianqi01 *Stu = &Stu{"tianqi01", 20, false}
	fmt.Println(*tianqi01) //{tianqi01 20 false}

	var tianqi02 *Stu = &Stu{}
	(*tianqi02).Name = "tianqi02"
	(*tianqi02).Age = 100
	(*tianqi02).Sex = false
	fmt.Println(*tianqi02) //{tianqi02 100 false}
	//类型推导  省略。。。。
}

type Stu struct {
	Name string
	Age  int
	Sex  bool
}
